package com.devunion.salon.server.jpa.utils;

import com.devunion.salon.client.app.bean.ProductModel;
import com.devunion.salon.client.app.bean.VendorModel;
import com.devunion.salon.client.app.bean.DepartmentModel;
import com.devunion.salon.client.app.bean.ProductHistoryModel;
import com.devunion.salon.core.model.*;

/**
 * @author spetrakovsky
 */
public class ObjectTransformer {

    public static Product translate(ProductModel productModel) {
        if (productModel == null) {
            return null;
        }
        Product product = new Product();
        product.setBarCode(productModel.getBarCode());
        product.setDescription(productModel.getDescription());
        product.setDiscount(productModel.isDiscount());
        product.setVendor(translate(productModel.getVendor()));
        product.setId(productModel.getId());
        product.setInventoryDepartment(translate(productModel.getInventoryDepartment()));
        product.setMarkup(productModel.getMarkup());
        product.setName(productModel.getName());
        product.setPrice(productModel.getPrice());
        product.setPriceOverrides(productModel.isPriceOverrides());
        product.setQty(productModel.getQty());
        product.setReorderAt(productModel.getReorderAt());
        product.setRetailPrice(productModel.getRetailPrice());
        product.setTaxable(productModel.isTaxable());
        product.setUom(productModel.getUom());
        return product;
    }

    public static ProductModel translate(Product product) {
         if (product == null) {
            return null;
        }
        ProductModel productModel = new ProductModel();
        productModel.setBarCode(product.getBarCode());
        productModel.setDescription(product.getDescription());
        productModel.setDiscount(product.isDiscount());
        productModel.setVendor(translate(product.getVendor()));
        productModel.setId(product.getId());
        productModel.setInventoryDepartment(translate(product.getInventoryDepartment()));
        productModel.setMarkup(product.getMarkup());
        productModel.setName(product.getName());
        productModel.setPrice(product.getPrice());
        productModel.setPriceOverrides(product.isPriceOverrides());
        productModel.setQty(product.getQty());
        productModel.setReorderAt(product.getReorderAt());
        productModel.setRetailPrice(product.getRetailPrice());
        productModel.setTaxable(product.isTaxable());
        productModel.setUom(product.getUom());
        return productModel;
    }

     public static ProductHistoryModel translate(ProductHistory product) {
         if (product == null) {
            return null;
        }
        ProductHistoryModel productModel = new ProductHistoryModel();
        productModel.setBarCode(product.getBarCode());
        productModel.setDescription(product.getDescription());
        productModel.setDiscount(product.isDiscount());
        productModel.setVendor(translate(product.getVendor()));
        productModel.setId(product.getId());
        productModel.setInventoryDepartment(translate(product.getInventoryDepartment()));
        productModel.setMarkup(product.getMarkup());
        productModel.setName(product.getName());
        productModel.setPrice(product.getPrice());
        productModel.setPriceOverrides(product.isPriceOverrides());
        productModel.setQty(product.getQty());
        productModel.setReorderAt(product.getReorderAt());
        productModel.setRetailPrice(product.getRetailPrice());
        productModel.setTaxable(product.isTaxable());
        productModel.setUom(product.getUom());
        productModel.setTime(product.getTime());
        return productModel;
    }

    public static DepartmentModel translate(InventoryDepartment department) {
        if (department == null) {
            return null;
        }
        DepartmentModel model = new DepartmentModel();
        model.setId(department.getId());
        model.setName(department.getName());
        return model;
    }

    public static InventoryDepartment translate(DepartmentModel model) {
        if (model == null) {
            return null;
        }
        InventoryDepartment department = new InventoryDepartment();
        department.setId(model.getId());
        department.setName(model.getName());
        return department;
    }

    public static VendorModel translate(Vendor vendor) {
        if (vendor == null) {
            return null;
        }
        VendorModel vendorModel = new VendorModel();
        vendorModel.setId(vendor.getId());
        //vendorModel.setAddress(vendor.getAddress().getAddress1());
        vendorModel.setCode(vendor.getCode());

        return vendorModel;
    }

    public static Vendor translate(VendorModel vendorModel) {
        if (vendorModel == null) {
            return null;
        }
        Vendor vendor = new Vendor();
        vendor.setId(vendorModel.getId());
        //vendorModel.setAddress(vendor.getAddress().getAddress1());
        vendor.setCode(vendorModel.getCode());
        return vendor;
    }
}
